package fileStudy;

import java.io.File;

public class files {
    static  int count1 = 0;

    static  int count2 = 0;
    public static void main(String[] args) {
        String filePath = "F:\\";
        //traverseFolder(filePath);
        System.out.println("一共有"+(count2+count1)+"个文件");
    }
    public static void traverseFolder(String path){

        File file = new File(path);
        if(file.exists()){
            File[] files = file.listFiles();
            if(files == null || files.length==0){
                System.out.println("不存在文件！");
                return;
            }
            else {
                for (File file1:files
                ) {
                    if(file1.isDirectory() && file1 != null){
                        System.out.println("文件夹："+file1.getAbsolutePath());
                        count1++;
                        traverseFolder(file1.getAbsolutePath());
                    }
                    else {
                        System.out.println("文件："+file1.getAbsolutePath());
                        count2++;
                    }
                }
            }
        }
        else {
            System.out.println("文件不存在！");
        }
    }
}
